package haxe.util.benchmark; 
import haxe.util.Queue;

class BenchmarkQueue extends BenchmarkHelper, implements Benchmark
{
	
	var s:haxe.util.Queue<Float>;
	
	public function new( iterations:Int ) 
	{
		super( iterations );
		s = new Queue<Float>();
	}
	
	private function runAdd():Void
	{
		s.clear();
		this.init( "Queue.add["+iterations+"]" );
		for ( i in 0...iterations )
			s.add(i);
		this.done();
	}
	
	private function runToArray():Void
	{
		s.clear();
		for ( i in 0...iterations )
			s.add(i);
		this.init( "Queue.toArray["+iterations+"]" );
		var a = s.toArray();
		this.done();
	}
	
	private function runIterate():Void
	{
		s.clear();
		for ( i in 0...iterations )
			s.add(i);
		this.init( "Queue.iterate["+iterations+"]" );
		for ( i in s ){i;}
		this.done();
	}
	
	private function runRemove():Void
	{
		s.clear();
		s = new Queue<Float>();
		var a:Array<Float> = new Array<Float>();
		var rand:Float;
		for ( i in 0...iterations )
		{
			rand = Math.random();
			s.add( rand );
			if ( i % 5 == 0 )
				a.push( rand );
		}
		this.init( "Queue.remove["+(iterations/5)+" from "+iterations+"]" );
		for ( i in a )
		{
			s.remove( i );
		}
		this.done();
	}
	
	private function runRemoveWithFunction():Void
	{
		s.clear();
		s = new Queue<Float>();
		var a:Array<Float> = new Array<Float>();
		var rand:Float;
		for ( i in 0...iterations )
		{
			rand = Math.random();
			s.add( rand );
			if ( i % 5 == 0 )
				a.push( rand );
		}
		var f = function(a:Float,b:Float):Bool{return a == b; };
		this.init( "Queue.remove( with function )["+(iterations/5)+" from "+iterations+"]" );
		for ( i in a )
		{
			s.remove( i, f );
		}
		this.done();
	}
	
	private function runPop():Void
	{
		s.clear();
		s = new Queue<Float>();
		for ( i in 0...iterations )
			s.add( Math.random() );
		init("Queue.pop["+iterations+"]");
		while( !s.isEmpty() )
			s.dequeue();
		done();
	}
	
	private function runContains():Void
	{
		s.clear();
		s = new Queue<Float>();
		var a:Array<Float> = new Array<Float>();
		var rand:Float;
		for ( i in 0...iterations )
		{
			rand = Math.random();
			s.add( rand );
			if ( i % 10 == 0 )
				a.push( rand );
		}
		this.init( "Queue.contains["+(iterations/10)+" from "+iterations+"]" );
		for ( i in a )
		{
			s.contains( i );
		}
		this.done();
	}
}